package com.bishe.o2oo.web.superadmin;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bishe.o2oo.entity.Area;
import com.bishe.o2oo.service.AreaService;

@Controller
@RequestMapping("/superadmin") 
// 和URL路由相关，想要调用controller的方法，必须在superadmin路径下调用
public class AreaController {
	@Autowired 
	// 在程序需要用到areaService时，将实现类注入进来
	private AreaService areaService;

	@RequestMapping(value = "/listarea", method = RequestMethod.GET)
	@ResponseBody 
	// 将modelmap自动转换成json对象返回给前端
	private Map<String, Object> listArea() {
		Map<String, Object> modelMap = new HashMap<String, Object>();// 存放方法返回值
		List<Area> list = new ArrayList<Area>();// 获取service层获取的区域列表
		try {
			list = areaService.getAreaList();
			modelMap.put("rows", list);
			modelMap.put("total", list.size());
		} catch (Exception e) {
			e.printStackTrace();
			modelMap.put("success", false);
			modelMap.put("errMsg", e.toString());
		}
		return modelMap;
	}
}
